package com.example.lisongyu;


import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;
import android.widget.TextView;

public class JinduActivity extends AppCompatActivity {
    private TextView idTvDjs;
    private ProgressBar idPb;

    private TextView idTvDjs2;
    private ProgressBar idPb2;

    int index = 10;
    Handler handler = null;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jdu);

        idPb = findViewById(R.id.idPb);
        idTvDjs = findViewById(R.id.idTvDjs);

        idPb2 = findViewById(R.id.idPb2);
        idTvDjs2 = findViewById(R.id.idTvDjs2);

        initHandler();
        new Timers().start();

    }

    private void initHandler() {
        handler = new Handler(){
            @Override
            public void handleMessage(@NonNull Message msg) {
                switch (msg.what){
                    case 110:
                       // Toast.makeText(JduActivity.this, "我收到了！"+index, Toast.LENGTH_SHORT).show();
                        idTvDjs.setText("广告"+index+"S");
                        idPb.setProgress(index);

                        int index2=10-index;
                        idTvDjs2.setText("广告"+index2+"S");
                        idPb2.setProgress(index2);

                        if(index==0){
                           // startActivity((JduduActivity.this,MainActivity2.class));
                            startActivity(new Intent(JinduActivity.this,MainActivity2.class));
                        }
                }
            }
        };
    }


    class Timers extends Thread{
        @Override
        public void run() {
            while(index>0){
                index--;
                Message message = handler.obtainMessage();
                message.what = 110;
                message.obj = index;
                handler.sendMessage(message);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
